package com.xb.cloud.merchantapi.product.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xb.cloud.gateway.client.ReturnCodes;
import com.xb.cloud.gateway.client.ReturnUtils;
import com.xb.cloud.gateway.client.RtnInfo;
import com.xb.cloud.merchantapi.product.service.FinanceApiService;
import com.xb.cloud.order.service.client.FinanceService;
import com.xb.cloud.product.merchant.service.client.EndMerchantUserService;
import com.xb.cloud.product.merchant.service.client.bo.EndMerchantUserBo;
import com.xb.cloud.service.client.ServiceReturnInfo;
import com.xb.cloud.service.client.ServiceReturnUtils;

@Service
public class FinanceApiServiceImpl implements FinanceApiService {
	@Resource
	private EndMerchantUserService endMerchantUserService;
	
	@Resource
	FinanceService financeService;
	
	@Override
	public RtnInfo getMerchantFinaceInfo(EndMerchantUserBo merchantUserBo) {
		
		ServiceReturnInfo merchantReturnInfo = endMerchantUserService.getEndMerchantUserById(merchantUserBo.getId());
		if (ServiceReturnUtils.isSuccess(merchantReturnInfo)) {
			if (merchantReturnInfo.getData() == null) {
				return ReturnUtils.error(ReturnCodes.MERCHANT_NOT_EXIST);
			} else {
				merchantUserBo = (EndMerchantUserBo) merchantReturnInfo.getData();
			}
		} else {
			return ReturnUtils.error(ReturnCodes.SYSTEM_EXCEPTION);
		}

		ServiceReturnInfo merchantFinaceInfo = financeService.getMerchantFinaceInfo(merchantUserBo);
		
		
		
		return ReturnUtils.success(merchantFinaceInfo.getData());
	}

}
